package com.atguigu.gmall.product.api;

import com.atguigu.gmall.common.constant.RedisConst;
import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.list.SearchAttr;
import com.atguigu.gmall.model.product.*;
import com.atguigu.gmall.product.service.ManagerService;
import com.atguigu.gmall.product.service.ProductDetailsApiService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.TimeUnit;

@Api(description = "商品详情页")
@RestController
@RequestMapping("/api/product")
public class ProductDetailsApiController {

    @Autowired
    private ProductDetailsApiService productDetailsApiService;

    @Autowired
    private ManagerService managerService;

    @Autowired
    @Qualifier("redis")
    private RedisTemplate redisTemplate;



    @ApiOperation("三级分类查询")
    @GetMapping("/getBaseCategoryView/{category3Id}")
    public BaseCategoryView getBaseCategoryView(@PathVariable Long category3Id){
        BaseCategoryView baseCategoryView = productDetailsApiService.getBaseCategoryView(category3Id);
        return baseCategoryView;
    }

    @ApiOperation("sku基本信息")
    @GetMapping("/getSkuInfo/{skuId}")
    public SkuInfo getSkuInfo(@PathVariable Long skuId){

        SkuInfo skuInfo = productDetailsApiService.getSkuInfo(skuId);
        return skuInfo;

    }

    @ApiOperation("销售属性与销售值")
    @GetMapping("/getSaleAttr/{spuId}/{skuId}")
    public List<SpuSaleAttr> getSpuSaleAttrAndValue(@PathVariable Long spuId,@PathVariable Long skuId){
        List<SpuSaleAttr> spuSaleAttrs= productDetailsApiService.getSpuSaleAttrAndValue(spuId,skuId);
        return spuSaleAttrs;
    }
    @ApiOperation("点击其他销售属性值的组合，跳转到另外的sku页面")
    @GetMapping("/getSkuValueIdsMap/{spuId}")
    public Map getSkuValueIdsMap(@PathVariable("spuId") Long spuId){

        return productDetailsApiService.getSkuValueIdsMap(spuId);
    }

    @ApiOperation("获取价格")
    @GetMapping("/getPrice/{skuId}")
    public BigDecimal getPrice(@PathVariable Long skuId){
        return productDetailsApiService.getPrice(skuId);
    }

    @ApiOperation("获取所有三级分类")
    @GetMapping("/getBaseCategoryList")
    public List<BaseCategoryView> getBaseCategoryList(){
     List<BaseCategoryView> list =    productDetailsApiService.getBaseCategoryList();
        return list;
    }


    @ApiOperation("根据ID查询品牌")
    @GetMapping("/baseTrademark/get/{id}")
    public BaseTrademark baseTrademarkById(@PathVariable Long id){
        BaseTrademark trademark = managerService.baseTrademarkById(id);
        return trademark;
    }

    @GetMapping("/getSearchAttrList/{skuId}")
    public List<SearchAttr> getSearchAttrList(@PathVariable  Long skuId){
        return productDetailsApiService.getSearchAttrList(skuId);
    }


    @GetMapping("/getBaseAttrInfoAndBaseAttrValue/{skuId}")
    public List<SkuAttrValue> getBaseAttrInfoAndBaseAttrValue(@PathVariable Long skuId){

        return productDetailsApiService.getBaseAttrInfoAndBaseAttrValue(skuId);
    }



}
